#ifndef GET_MSG_H
#define GET_MSG_H

#include "http_post.h"

class Get_Msg : public Http_Post
{
	Q_OBJECT
public:
	Get_Msg(Http_Post *parent = 0);
	~Get_Msg();


	QString fromUserName() const { return m_fromUserName; }
	void setFromUserName(const QString & fromUserName);

	QString toUserName() const { return m_toUserName; }
	void setToUserName(const QString & toUserName);

	QStringList syncKey() const { return m_syncKey; }

	bool needSaveLog() const { return m_needSaveLog; }
	void setNeedSaveLog(bool needSaveLog);

	Q_INVOKABLE void postV2(QString uin, QString sid, QString skey, QStringList syncKey);
	Q_INVOKABLE QString contentWithoutUserName(QString content);
	Q_INVOKABLE QString contentToUserName(QString content, QString oriUserName);

Q_SIGNALS:
	void fromUserNameChanged();
	void toUserNameChanged();
	void error();
	void received(QString content, QString userName);
	void newMsg(QString content, QString fromUserName, QString toUserName);
	void msg_ok(QStringList sync_key);
	void noNewMsg();
	void needSaveLogChanged();


	void received_msg(int createTime, QString fromUserName, QString toUserName, QString content);


protected:
	void finished(QNetworkReply* reply);

private:
	void m_saveLog(QString createTimeStr, QString fromUserName, QString content);
	void m_post(QString host, QString uin, QString sid, QString skey, QStringList syncKey);
	void m_handleNewMsg(QString msgId, QString content, QString fromUserNameStr, QString toUserNameStr, int createTime);

private:
	QString m_fromUserName = "";
	QString m_toUserName = "";
	QMap<QString, int> m_map;
	QStringList m_syncKey;
	bool m_needSaveLog = true;
	bool m_v2 = false;
	QString m_skey = "";
};

#endif // GET_MSG_H
